using System;
using System.Collections.Generic;
using System.Text;

namespace Wrath.Xml.Objects
{
    public class WindowClassPlacement : IElementContainer
    {
        Size size = null;
        Position position = null;

        public WindowClassPlacement(Element element)
        {
            Element subElement = element.FindFirstElement("size", false);
            if (subElement != null)
            {
                try { size = new Size(subElement); }
                catch { size = null; }
            }

            subElement = element.FindFirstElement("position", false);
            if (subElement != null)
            {
                try { position = new Position(subElement); }
                catch { position = null; }
            }
        }

        #region IElementContainer Members

        private Element sourceElement;
        public Element SourceElement
        {
            get { return sourceElement; }
        }

        public void Commit()
        {
            sourceElement = new Element("placement");

            if (size != null)
            {
                size.Commit();
                sourceElement.ChildElements.Add(size.SourceElement);
            }

            if (position != null)
            {
                position.Commit();
                sourceElement.ChildElements.Add(position.SourceElement);
            }
        }

        #endregion
    }
}
